home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / PATRON.ZIP / OLEINS.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  4KB  |  162 lines

  1. /*
  2.  * OLEINS.C
  3.  *
  4.  * Functions to handle the Insert Object command as well as the
  5.  * Insert Object dialog.  Calls functions in REGISTER.C to query
  6.  * the registration database for object classnames.
  7.  *
  8.  * Also contains the FObjectsFromDropFiles function to create embedded
  9.  * Packager objects from files dropped from File Manager.
  10.  *
  11.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  12.  */
  13.  
  14. #include <windows.h>
  15. #include <ole.h>
  16. #include "register.h"
  17. #include "oclient.h"
  18.  
  19.  
  20.  
  21. /*
  22.  * PObjectInsertDialog
  23.  *
  24.  * Purpose:
  25.  *  Displays the Insert Object dialog and creates an object of the
  26.  *  selected name.  The caller must provide the name of the object
  27.  *  to create.  NOTE:  Uses pDoc->pszData1.
  28.  *
  29.  * Parameters:
  30.  *  hWnd            HWND parent of the dialog box.
  31.  *  hInst           HANDLE of the application instance.
  32.  *  pDoc            LPDOCUMENT identifying OLE data.
  33.  *  pszObject       LPSTR to the name for a new object.
  34.  *
  35.  * Return Value:
  36.  *  LPOBJECT        Pointer to a new OBJECT if the function succeeds.
  37.  *                  NULL otherwise or if the user pressed Cancel.
  38.  */
  39.  
  40. LPOBJECT FAR PASCAL PObjectInsertDialog(HWND hWnd, HANDLE hInst,
  41.                                         LPDOCUMENT pDoc, LPSTR pszObject)
  42.     {
  43.     FARPROC         lpfn;
  44.     WORD            wTemp;
  45.     BOOL            fTemp;
  46.     LPOBJECT        pObj;
  47.     OLESTATUS       os;
  48.  
  49.     if (NULL==pszObject)
  50.         return NULL;
  51.  
  52.     /*
  53.      * Pass a string pointer to the dialog in which the it will return
  54.      * the object class name.
  55.      */
  56.  
  57.     lpfn=MakeProcInstance(InsertObjectProc, hInst);
  58.     wTemp=DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INSERTOBJECT), hWnd,
  59.                          lpfn, (LONG)pDoc->pszData1);
  60.     FreeProcInstance(lpfn);
  61.  
  62.     //Out of memory==-1, User pressed cancel==0
  63.     if (1!=wTemp)
  64.         return NULL;
  65.  
  66.     pObj=PObjectAllocate(&fTemp, pDoc);
  67.  
  68.     if (!fTemp)
  69.         {
  70.         PObjectFree(pDoc, pObj);
  71.         return NULL;
  72.         }
  73.  
  74.     //Attempt to launch the server to give us the object.
  75.     os=OleCreate(PSZOLE(IDS_STDFILEEDITING), (LPOLECLIENT)pObj, pDoc->pszData1,
  76.                  pDoc->lh, pszObject, &pObj->pObj, olerender_draw, 0);
  77.  
  78.     if (OLE_OK!=OsError(os, pDoc, pObj, TRUE))
  79.         {
  80.         MessageBox(hWnd, PSZOLE(IDS_NOINSERT), PSZOLE(IDS_INSERTTITLE),
  81.                    MB_OK | MB_ICONEXCLAMATION);
  82.  
  83.         PObjectFree(pDoc, pObj);
  84.         return NULL;
  85.         }
  86.     else
  87.         {
  88.         //Mark this guy as open.
  89.         pObj->fOpen=TRUE;
  90.         }
  91.  
  92.     return pObj;
  93.     }
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /*
  100.  * InsertObjectProc
  101.  *
  102.  * Purpose:
  103.  *  Dialog procedure for the Insert Object dialog.
  104.  *
  105.  * Parameters:
  106.  *  The standard.
  107.  *
  108.  * Return Value:
  109.  *  The value to be returned through the DialogBox call that
  110.  *  created the dialog.
  111.  *
  112.  */
  113.  
  114. BOOL FAR PASCAL InsertObjectProc(HWND hDlg, WORD iMsg, WORD wParam, LONG lParam)
  115.     {
  116.     static LPSTR    pszObject;
  117.     WORD            i;
  118.     WORD            cb;
  119.     HWND            hList;
  120.     char            szTemp[256];
  121.  
  122.     switch (iMsg)
  123.         {
  124.         case WM_INITDIALOG:
  125.             pszObject=(LPSTR)lParam;
  126.  
  127.             //Go fill the listbox with names from the registration database.
  128.             hList=GetDlgItem(hDlg, ID_OBJECTLIST);
  129.             WFillClassList(hList);
  130.             return TRUE;
  131.  
  132.  
  133.         case WM_COMMAND:
  134.             switch (wParam)
  135.                 {
  136.                 case IDCANCEL:
  137.                     EndDialog(hDlg, FALSE);
  138.                     break;
  139.  
  140.                 //Double-clicking is the same as hitting OK.
  141.                 case ID_OBJECTLIST:
  142.                     if (LBN_DBLCLK!=HIWORD(lParam))
  143.                         break;
  144.  
  145.                     //FALL THROUGH.
  146.  
  147.                 case IDOK:
  148.                     hList=GetDlgItem(hDlg, ID_OBJECTLIST);
  149.                     i=(WORD)SendMessage(hList, LB_GETCURSEL, 0, 0L);
  150.  
  151.                     //Convert the descriptive name to a real classname.
  152.                     SendMessage(hList, LB_GETTEXT, i, (LONG)(LPSTR)szTemp);
  153.                     cb=WClassFromDescription(szTemp, pszObject, 256);
  154.  
  155.                     EndDialog(hDlg, TRUE);
  156.                     break;
  157.                 }
  158.             break;
  159.         }
  160.     return FALSE;
  161.     }
  162.